#include "main.h"

void QMyLabel::rsetText(QListWidgetItem *item)
{
    this->setText(item->text());
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget widget;
    widget.setWindowTitle("QWidget窗口");//设置窗口标题
    widget.resize(500,500);
    QListWidget list_widget(&widget);
    list_widget.resize(500,400);
    list_widget.setFont(QFont("宋体",14));
    list_widget.addItem("C语言中文网");
    list_widget.addItem("http://c.biancheng.net");
    list_widget.addItem(new QListWidgetItem("Qt教程"));
    QMyLabel print;
    print.setText("选中内容");
    print.setParent(&widget);
    print.resize(500,100);
    print.move(0,400);
    print.setAlignment(Qt::AlignHCenter);
    QObject::connect(&list_widget,&QListWidget::itemClicked,&print,&QMyLabel::rsetText);
    widget.show();

    return a.exec();
}
